package com.bobo.serviceorder.config;

import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author bobo
 * @date 2021-04-13
 */
@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate<Integer, Integer> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<Integer, Integer> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        return redisTemplate;
    }

    @Bean
    public Redisson redisson() {
        Config config = new Config();
        config.useSingleServer().setAddress("127.0.0.1:6379").setDatabase(0);
        return (Redisson) Redisson.create(config);
    }

    @Autowired
    RedisSentinelProperties properties;

//    @Bean
//    @Order(1)
//    public Redisson redissonSentinel() {
//
//        Config config = new Config();
//        config.useSentinelServers()
//                .setMasterName(properties.getMasterName())
//                .addSentinelAddress(properties.getAddress())
//                .setDatabase(0);
//        return (Redisson) Redisson.create(config);
//    }

    @Bean
    public Redisson redisson1() {
        Config config = new Config();
        config.useSingleServer().setAddress("127.0.0.1:6379").setDatabase(0);
        return (Redisson) Redisson.create(config);
    }

    @Bean
    public Redisson redisson2() {
        Config config = new Config();
        config.useSingleServer().setAddress("127.0.0.1:6380").setDatabase(0);
        return (Redisson) Redisson.create(config);
    }

    @Bean
    public Redisson redisson3() {
        Config config = new Config();
        config.useSingleServer().setAddress("127.0.0.1:6381").setDatabase(0);
        return (Redisson) Redisson.create(config);
    }
}
